<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./index.css">
</head>
<body>
    <div>
        <h1>留言板</h1>
        <ul></ul>
        <textarea placeholder="请编辑您的留言"></textarea>
        <button class="sub">发布</button>
    </div>
</body>
</html>
<script>
    var btn=document.querySelector('.sub')
    var text=document.querySelector('.textarea')
    var ul=document.querySelector('ul')
    btn,onclick=function(){
        if(text.value==''){
            alert('你没有输入内容')
            return false
        }else{
            var li=document.createElement('li')
            li.innerHTML=text.value
            var button=document.createElement('button')
            button.className='remove'
            button.innerHTML='删除'
            button.onclick=function(){
                ul.removeChild(this.parentNode)
            }
            ul.appendChild(button)
            ul.insertBefore(li,ul.children[0])
            text.value=''
        }
    }
</script>